package com.xiaoyin.community.Controller;

import com.xiaoyin.community.Domain.Candicate;
import com.xiaoyin.community.Service.CandicateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * Created by yinjianping@baidu.com on 2018/7/11.
 *
 * @Description:
 * @Modified By:
 */
@RestController
public class CandicateController {
    @Autowired
    private CandicateService candicateService;

    @GetMapping(value = "/findOne/{id}")
    public Candicate findOne(@PathVariable("id") Integer id){
        return candicateService.findOneService(id);
    }

    @GetMapping(value = "/findTest")
    public Candicate Test(@RequestParam(name = "id",defaultValue = "") String id){
        return candicateService.findOneService(Integer.valueOf(id));
    }
    @GetMapping(value = "/findByName/{name}")
    public List<Candicate> findByName(@PathVariable("name") String name){
        return candicateService.findByNameService(name);
    }

    @PostMapping(value = "/save")
    public Candicate saveOne(@RequestParam("candicateId") Integer candicateId,
                             @RequestParam("candicateName") String candicateName,
                             @RequestParam("candicateClass") String candicateClass,
                             @RequestParam("candicatePhone") String candicatePhone){

        Candicate candicate = new Candicate();
        candicate.setCandicateId(candicateId);
        candicate.setCandicateName(candicateName);
        candicate.setCandicateClass(candicateClass);
        candicate.setCandicatePhone(candicatePhone);

        return  candicateService.saveService(candicate);
    }

//    @PostMapping(value = "/save")
//    public Result<Candicate> saveOne(@Valid Candicate candicate, BindingResult bindingResult){
//        if (bindingResult.hasErrors()){
//            return ResultUtils.error(0,bindingResult.getFieldError().getDefaultMessage());
//        }
//        candicate.setCandicateId(candicate.getCandicateId());
//        candicate.setCandicateName(candicate.getCandicateName());
//        candicate.setCandicateClass(candicate.getCandicateClass());
//        candicate.setCandicatePhone(candicate.getCandicatePhone());
//
//        return ResultUtils.success(candicateService.saveService(candicate));
//    }
}
